//
//  UIButton+Extra.h
//  Voxper
//
//  Created by Erphan on 2/8/11.
//  Copyright 2011 Smonte. All rights reserved.
//

@interface UIButton(Extra)
- (void)buttonWithTitle:(NSString *)title fontSize:(int)fontSize target:(id)target selector:(SEL)selector image:(UIImage *)image imagePressed:(UIImage *)imagePressed darkTextColor:(BOOL)darkTextColor;
@end

@implementation UIButton(Extra)
- (void)buttonWithTitle:(NSString *)title fontSize:(int)fontSize target:(id)target selector:(SEL)selector image:(UIImage *)image imagePressed:(UIImage *)imagePressed darkTextColor:(BOOL)darkTextColor {	
	self.backgroundColor = [UIColor clearColor];
	self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
	self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
	self.titleLabel.textColor = (darkTextColor) ? [UIColor blackColor] : [UIColor whiteColor];
	self.titleLabel.shadowColor = (!darkTextColor) ? [UIColor blackColor] : [UIColor whiteColor];
	self.titleLabel.shadowOffset = CGSizeMake(1, 1);	
	self.titleLabel.font = [UIFont boldSystemFontOfSize:fontSize];
	
	UIImage *newImage = [image stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
	[self setBackgroundImage:newImage forState:UIControlStateNormal];
	
	if (imagePressed)
	{
		UIImage *newPressedImage = [imagePressed stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
		[self setBackgroundImage:newPressedImage forState:UIControlStateHighlighted];
	}
	
	[self setTitle:title forState:UIControlStateNormal];
	[self addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
}
@end